package admin_api

import (
	"github.com/gin-gonic/gin"
	"shop/admin/admin_service"
	"shop/entity"
	"shop/utils/convertutil"
	"shop/utils/result"
	"shop/utils/sessionutil"
)

func GetShopConfig(c *gin.Context) {
	result.RenderResult(c, admin_service.GetShopConfig(sessionutil.GetShopIdFromCtx(c)))
}

func UpdateShopConfig(c *gin.Context) {
	shop := new(entity.ShopFilter)
	if err := c.ShouldBindJSON(shop); err != nil {
		result.RenderFail(c, "参数格式错误："+err.Error())
		return
	}

	result.RenderResult(c, admin_service.UpdateShopConfig(sessionutil.GetShopIdFromCtx(c), shop))
}

func GetShopList(c *gin.Context) {
	result.RenderResult(c, admin_service.GetShopList(sessionutil.GetSysUserInfo(sessionutil.GetSysUserIdFromCtx(c))))
}

func AddShop(c *gin.Context) {
	shop := new(entity.Shop)
	if err := c.ShouldBindJSON(shop); err != nil {
		result.RenderFail(c, "参数格式错误："+err.Error())
		return
	}

	result.RenderResult(c, admin_service.AddShop(shop))
}

func UpdateShop(c *gin.Context) {
	shop := new(entity.ShopFilter)
	if err := c.ShouldBindJSON(shop); err != nil {
		result.RenderFail(c, "参数格式错误："+err.Error())
		return
	}

	result.RenderResult(c, admin_service.UpdateShop(convertutil.ParseInt(c.Param("id")), shop))
}
